from typing import Any, Annotated
from datetime import timedelta,datetime
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from fastapi import APIRouter, Depends, HTTPException, status, Path
from sqlalchemy.orm.session import Session
from common.deps import check_jwt_token, get_db
from core.response import response_code
from datetime import datetime
from setting.web import settings
from core.schemas.xclass import ClassCreate,AddStudent
import crud

router = APIRouter()

@router.post("/add", summary="添加班级")
async def add_class(new_class:ClassCreate,db: Session = Depends(get_db),payload=Depends(check_jwt_token)):
    res = crud.xclass.add_class(db,new_class)
    return response_code.resp_200(data=res)

@router.get("/list", summary="列出班级")
async def list_class(page: int = 1, pageSize: int = 20,  db: Session = Depends(get_db),payload=Depends(check_jwt_token)):
    res = crud.xclass.list_class(db,page,pageSize)
    return response_code.resp_200(data=res)

@router.get("/getClass", summary="获取班级")
async def list_class(class_id: int,  db: Session = Depends(get_db),payload=Depends(check_jwt_token)):
    res = crud.xclass.get_class(db,class_id)
    return response_code.resp_200(data=res)

@router.get("/listClassStudent", summary="获取班级")
async def list_class_student(page: int = 1, pageSize: int = 20,class_id:int =1, db: Session = Depends(get_db),payload=Depends(check_jwt_token)):
    res = crud.xclass.list_class_student(db,page,pageSize,class_id)
    return response_code.resp_200(data=res)

@router.post("/addClassStudent", summary="添加学生")
async def add_class_student(info:AddStudent, db: Session = Depends(get_db),payload=Depends(check_jwt_token)):
    res = crud.xclass.add_student(db,info.user_id,info.class_id)
    return response_code.resp_200(data=res)